<template>
  <!-- 字典项管理 -->
  <div class="box">
    <avue-crud :ref="refName"
               :option="option"
               :page="page"
               :table-loading="tableLoading"
               @row-update="handleUpdate"
               @row-save="handleSave"
               @row-del="rowDel"
               @size-change="sizeChange"
               @current-change="currentChange"
               @refresh-change="refreshChange"
               @search-reset="searchChange"
               @search-change="searchChange"
               v-model="form"
               :data="tableData">
    </avue-crud>
  </div>
</template>

<script setup>
import {option} from '@/table/sys/dict/itemDict.js'

const httpService = inject("httpService")
const util = inject('util')

//接收父组件的值
const props = defineProps({
  dictId: String,
})

//定义计算函数，保证外部发送变化，useTableMixins主键内部也能变化
const dictId = computed(() => props.dictId)

//监听dictId变化
watch(dictId, (newId) => {
  if (util.isEmpty(newId)) {
    tableData.value = [];
    return;
  }
  getList();
})
const {
  form,
  page,
  refName,
  tableData,
  tableLoading,
  handleSave,
  handleUpdate,
  rowDel,
  searchChange,
  refreshChange,
  sizeChange,
  currentChange,
  activated,
  buttonPermissionsCheck,
  getList,
} = useTableMixins(option, "sys-dict-item", {
  isGetList: false,
  defaultParameter: {
    dictId
  },
  saveDefaultParameter: {
    dictId
  },
  page: {
    total: 0,  // 总记录数
    currentPage: 1,  // 当前页数
    pageSize: 20,  // 每页显示多少条
    sortdatafield: "sort",  // 排序字段名
    sortorder: "asc"  // 排序方式 asc/desc
  },
})

onActivated(() => {
  activated()
})
</script>

<style scoped>

</style>
